// 用两条链表，一条放值小于 val 的节点，一条放值大于 val 的节点
// 最后合并两天链表

var partition = function (head, x) {
  let before = beforeHead = new ListNode(-1);
  let after = afterHead = new ListNode (-1);
  while (head) {
    if (head.val < x) before = beforeHead = head;
    else after = afterHead = head;
    after = after.next;
  }
  after.next = null;
  before.next = afterHead.next;
  return beforeHead.next;
}